<template>
	<view class="body">
		<view class="personal">
			<view class="content">
				<view class="heandimg" @click="personalone">
					<text style="color: #454545;">头像</text>
					<image :src="head" class="toxian"></image>
				</view>
				<view class="nickname" @click="mingcheng">
					<text style="color: #454545;">昵称</text>
						<view class="nickname1">{{nickname}}
						   <image class="qiantou" src="../../static/img/more.png"></image>
						</view>
				</view>
				<view class="numberid">
					<text style="color: #454545;">ID</text>
					<text class="number">{{uid}}</text>
					<!-- <text class="number">1234567</text> -->
				</view>
			</view>
		</view>
		<button style="background-color: #3C6DD2;margin-top: 100upx;" @click="save">保存</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				uid:'',
				head:'',
				nickname:'',
				type:'',
				pic:'',
				ID:'',
				head1:'',
				image:''
			};
		},
		methods: {
			personalone () {
				uni.chooseImage({
					count: 1,
					sizeType: ['original'],
					sourceType: ['album','camera'], 
			        success: (res) => {
						const tempFilePaths  = res.tempFilePaths ;
						uni.uploadFile({
							url:'http://xj.gccrw.cn/api/user/uploadFile',
							 filePath: tempFilePaths [0],
							name:'pic',
							data:{
								type:1,
								pic:tempFilePaths 
							},
							method:'POST',
							success: (ret) => {
								console.log('------1122321',ret.data);
								this.head1 = ret.data
							}
						})
				    }
				})
			},
			getData () {
				uni.request({
					url:'http://xj.gccrw.cn/api/index/login',
					data:{
						name:this.name,
						password:this.possword
					},
					method:'POST',
					success: (res) => {
						this.nickname = res.data.data.user.nickname;
						this.head = res.data.data.user.head;
						this.uid = res.data.data.user.uid;
					}
					
				})
			},
			mingcheng () {
				uni.request({
						url: 'http://xj.gccrw.cn/api/index/login',
						data: {
							name:this.name,
							password:this.possword
						},
						method: "POST",
						success: (res) => {
							uni.navigateTo({
								url: '/pages/nickname/nickname?name=' +  res.data.data.user.name + '&pw=' + res.data.data.user.pw
								     + '&uid=' + res.data.data.user.uid,
							})
					}
				})
			},
			save () {
				const headimg = JSON.parse(this.head1);
				uni.request({
					url:'http://xj.gccrw.cn/api/user/saveInfo',
					data:{
						uid:uni.getStorageSync('uid'),
						head:headimg,
						nickname:this.nickname
					},
					method:'POST',
					success: (res) => {
						console.log('----1111',)
						uni.navigateBack({
						    delta:1
						})
					}
				})
			}
		},
		onShow () {
			this.getData ()
		},
		onLoad (e) {
			console.log('-------555-----',e.uid);
			this.name = e.name;
			this.possword = e.pw;
		}
	}
</script>

<style>
.personal {
	width: 100%;
	height: 410upx;
	display: flex;
}
.heandimg {
	display: flex;
	border-bottom: 2upx solid #F3F3F3;
	align-items: center;
	padding: 0upx 20upx 20upx 20upx;
}
.toxian {
	width: 124upx;
	height: 124upx;
	margin-left: 64%;
	border: 6upx solid #FFFFFF;
    border-radius: 50%;
	background-color: #E3E3E3;
}
.nickname {
	display: flex;
	border-bottom: 2upx solid #F3F3F3;
	padding: 20upx;
	justify-content: space-between;
}
.nickname1 {
	color: #B5B5B5;
	display: flex;
	align-items: center;
}
.qiantou {
	width: 20upx;
	height: 40upx;
	margin-left: 7upx;
	margin-top: 7upx;
}
.numberid {
	display: flex;
	justify-content: space-between;
	padding: 20upx;
}
.number {
	color: #B5B5B5;
	width: 170upx;
	overflow: hidden;
	text-overflow: ellipsis;
}
</style>
